package com.ztesoft.book.core.sys.sysuser.dto;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.ztesoft.book.common.constant.CommonParamUtil;
import com.ztesoft.book.core.base.base.dto.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description: 系统用户实体类
 * @Author: YangFan
 * @Date: 2021-03-22 14:23
 */
@Data
@TableName("sys_user")
@EqualsAndHashCode(callSuper = true)
public class SysUserDTO extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    private String username;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空")
    private String password;

    /**
     * 盐
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String salt;

    /**
     * 是否修改过密码
     */
    private Integer modifyPwd;

    /**
     * 修改密码时的时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime modifyPwdTime;

    /**
     * 邮箱
     */
    @Email(message = "邮箱格式不正确")
    private String email;

    /**
     * 手机号
     */
    @NotBlank(message = "用户昵称不能为空")
    private String nickName;

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 状态  0：正常   1：锁定
     */
    private Integer status;

    /**
     * 密码错误次数
     */
    private Integer wrongPwdTimes;

    /**
     * 账户锁定时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime userLockTime;

    /**
     * 头像
     */
    private String logo;


    /*********************************************非数据库字段*********************************************/


    /**
     * 角色ID列表
     */
    @TableField(exist = false)
    private List<String> roleIdList;


    @TableField(exist = false)
    private String roleId;

    /**
     * 是否管理员
     */
    @TableField(exist = false)
    private Boolean isAdmin;

    /**
     * 最近一次登录时间
     */
    @TableField(exist = false)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = CommonParamUtil.NORMAL_FORMAT)
    @JsonFormat(pattern = CommonParamUtil.NORMAL_FORMAT)
    private LocalDateTime loginTime;

}
